package cn.net.isir.service;

import cn.net.isir.utils.StringUtils;
import cn.net.isir.core.BasicService;
import cn.net.isir.core.SetBasicDao;
import cn.net.isir.dao.TicketDao;
import cn.net.isir.entity.Ticket;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class TicketService extends BasicService<Ticket> {
    @SetBasicDao
    @Resource
    private TicketDao ticketDao;

    /**
     * 根据ticket获取内容
     *
     * @param ticket 票
     * @return 结果
     */
    public Ticket selectByTicket(String ticket) {
        return ticketDao.selectByTicket(ticket);
    }

    /**
     * 生成ticket
     *
     * @return 票
     */
    public String GenerTicket() {
        String ticket = StringUtils.randomByTime();
        Ticket t = new Ticket();
        t.setTicket(ticket);
        t.setStatus("unused");
        insert(t);
        return ticket;
    }

}
